#pragma once

#include "stdafx.h"

typedef std::basic_string<TCHAR> string_t;
class MenuButton;
class CGdiPlusBitmap;

class MenuButton
{
public:
	//current only support two state
	enum BUTTON_STATE 
	{
		NORMAL_STATE = 0,
		HOVER_STATE = 1,
		PRESSED_STATE = 2,
	};

	enum BUTTON_TYPE
	{
		TEXT_BUTTON = 0,
		ICON_BUTTON = 1,
	};


private:
	const static int MAX_TEXT_LENGTH = 10;
	static TCHAR m_szClassName[MAX_PATH];
	static bool m_fRegistered;
	static std::map<HWND, MenuButton*> m_handleMap;
	static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);


	HWND m_hWnd;
	HWND m_hParent;
	HMENU m_hMenu;
	BUTTON_STATE m_fButtonState;
	BUTTON_TYPE m_fButtonType;
	string_t	m_strButtonName;
	std::vector<string_t> m_buttonFiles;
	std::vector<CGdiPlusBitmap*> m_buttonImages;

	TCHAR m_lpMenuText[MAX_TEXT_LENGTH];
	int m_xPos;
	int m_yPos;
	
	bool RegisterButtonClass();
	void PaintMenuButton(HWND hwnd, HDC hdc);
	void PaintTextButton(HWND hwnd, HDC hdc);
	void createIcons();
	void PaintIconButton(HWND hwnd, HDC hdc);

	void OnMouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam);
	void OnMouseLeave(HWND hwnd, WPARAM wParam, LPARAM lParam);
	void OnTimer(HWND hwnd, WPARAM wParam, LPARAM lParam);
	void OnLButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);

	void createMenus();

public:
	//text button
	MenuButton( const string_t &buttonName, LPCTSTR lpText, int x, int y, int nWidth, int nHeight, HWND hParent );

	//icon button
	MenuButton( const string_t &buttonName, const std::vector<string_t> filePaths, int x, int y, int nWidth, int nHeight, HWND hParent );
	//MenuButton( const string_t &buttonName, LPCTSTR *lpIconPaths, int x, int y, HWND hParent);
};